package com.htthorizon.util;

import com.alibaba.fastjson.JSON;
import com.htthorizon.common.core.constant.Constants;
import com.htthorizon.common.core.domain.R;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author xu
 * @remark
 */
public class HttpTest {

    private static final String URL_PATTERN = Constants.HTTP+"%s%s%s";

    private static final String executeLogPath="/job/openApi/jobExecuteLog";

    protected static final Logger logger = LoggerFactory.getLogger(HttpTest.class);

    /**
     * 远程保存执行日志
     * @param instanceId
     * @param ruleId
     * @param serverAddress
     * @return
     */
    public static String saveExecuteLog(Long instanceId,String ruleId,String serverAddress){
        try {
            R<Object> objectR = new R<>();
            objectR.setCode(Constants.SUCCESS);
            objectR.setMsg("test test test !!!");
            String json = JSON.toJSONString(objectR);
            String url = String.format(URL_PATTERN, serverAddress, executeLogPath, "/save");
            logger.info("request url:"+url);
//            String result = HttpRequestUtils.postJson(url, json);
//            logger.info("save execute_log success:"+result);

            RequestBody body = (new FormBody.Builder()).add("jobId", "111").add("appId", "222").build();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("/openApi/jobExecuteLog任务实例执行日志调用失败：",e);
        }
        return Constants.FAIL.toString();
    }
}
